<template>
  <view class="chat-item" @click="toLink(`/packagePages/chatIm/chat`,item)">
    <view class="flex">
      <view class="positionRelative">
        <uv-avatar :src="item.userInfo.avatarUrl" size="60"></uv-avatar>
        <view class="newIcon">
          <uv-image src="https://cos.qcshejiao.com/qc/xcxui/ig/02292.png" width="35px" height="35px"></uv-image>
        </view>
      </view>
      <view class="chat-content flex alignCenter justifyBetween">
        <view class="">
          <view class="name bold fz16">{{item.userInfo.nickname}}</view>
          <view class="text fz14">{{desc_format(item.lastMessage)}}</view>
          <view class="fz12 time">{{proxy.$utils.im_time_format(item.lastMessage.time)}}</view>
        </view>
        <!-- {{item.unread}} -->
        <view class="dot shrink" v-if="item.unread"></view>
      </view>
    </view>
  </view>
</template>

<script setup lang="ts">
const { proxy } = getCurrentInstance();
let props = defineProps(["item"]);

let item = computed(() => {
  return props.item;
});

function desc_format(e) {
  if (!e) return;
  if (e.type == "text") return proxy.$utils.truncateString(e.body.text, 10);
  if (e.type == "image") return "[图片]";
  if (e.type == "audio") return "[语音]";
  if (e.type == "location") return "[位置]";
}

function toLink(path, row) {
  let { lastMessage } = row;
  let url = proxy.$utils.buildUrl(path, {
    userId:
      lastMessage.from == lastMessage.userId
        ? lastMessage.to
        : lastMessage.from,
  });
  proxy.$utils.toLink(url);
}
</script>



<style lang="scss" scoped>
.chat-item {
  background-color: white;
  padding: 15px;
  border-radius: 15px;
  .newIcon {
    position: absolute;
    right: -10px;
    bottom: -5px;
  }
  .chat-content {
    margin-left: 15px;
    width: 100%;
    .name {
      color: #2d3f7b;
    }
    .time {
      color: #1877f2;
    }
    .text {
      color: #2d3f7b;
      padding: 2px 0;
    }
  }
  .dot {
    background-color: #1877f2;
    border-radius: 50%;
    width: 15px;
    height: 15px;
  }
}
</style>

